<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

    import {baseUploadUrl} from "@/config/env";
    export default {
        data() {
            return {
                obj: {},
                isIdFind: true,
                initSuccess: false,
            }
        },
        props: {
            closeDialog: [],
            uri: {},
            rowData: {},
        },
        computed: {
            option() {
                return {
                    submitBtn: true,
                    emptyBtn: true,
                    submitText: '提交',
                    emptyText: "关闭",
                    column: [
                        {
                            label: '单价',
                            prop: 'unitPrice',
                            type: 'number',
                            precision: 2,  //保留小数位,
                            minRows: 0,
                            maxRows: 99999999,
                            row: true,
                            span: 20,
                            disabled: true,
                            rules: [{
                                required: true,
                                message: "请输入 单价",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '购买数量',
                            prop: 'num',
                            type: 'number',
                            precision: 0,  //保留小数位,
                            minRows: 0,
                            maxRows: 99999999,
                            row: true,
                            span: 20,
                            disabled: true,
                            rules: [{
                                required: true,
                                message: "请输入 购买数量",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '总价',
                            prop: 'totalPrice',
                            type: 'number',
                            precision: 2,  //保留小数位,
                            minRows: 0,
                            maxRows: 99999999,
                            showWordLimit: true,
                            disabled: true,
                            span: 20,
                            rules: [{
                                required: true,
                                message: "请输入 总价",
                                trigger: "blur"
                            }]
                        },

                        {
                            label: '物流单号',
                            prop: 'logisticsNo',
                            maxlength: 20,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 物流单号",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '平台备注 ',
                            prop: 'platformRemark',
                            maxlength: 256,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 平台备注 ",
                                trigger: "blur"
                            }]
                        },
                    ]
                }
            }
        },
        created() {
            if (this.isIdFind) {
                this.findId(this.rowData);
            } else {
                this.obj = this.rowData;
                this.initSuccess = true;
            }
        },
        methods: {
            emptytChange() {
                console.log("=================================")
                this.closeDialog(false);
            },
            submit(form, done) {
                this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                    console.debug(res);
                    if (res.data.code == 200) {
                        this.closeDialog(true);
                    }
                    done(form);
                }).catch(err => {
                    console.error(err);
                    done(form);
                })
            },
            findId(rowData) {
                if (rowData != null && rowData.id != null) {
                    this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                         this.obj = res.data.data;
                         this.initSuccess = true;
                    })
                }
             }
        }
    }
</script>
